using System.Collections.Generic;
using UnityEngine;

namespace NodeCanvas.BehaviourTrees
{
	[AddComponentMenu("")]
	[Category("Mutators (beta)")]
	[Name("Node Toggler")]
	[Description("Enable, Disable or Toggle one or more nodes with provided tag. In practise their incomming connections are disabled\nBeta Feature!")]
	public class BTNodeToggler : BTNodeBase
	{
		public enum Mode
		{
			Enable = 0,
			Disable = 1,
			Toggle = 2
		}

		public Mode mode = Mode.Toggle;

		public string targetNodeTag;

		private List<Node> targetNodes;

		protected override Status OnExecute(Component agent, Blackboard blackboard)
		{
			targetNodes = base.graph.GetNodesWithTag<Node>(targetNodeTag);
			if (targetNodes.Count != 0)
			{
				if (mode == Mode.Enable)
				{
					foreach (Node targetNode in targetNodes)
					{
						targetNode.inConnections[0].isActive = true;
					}
				}
				if (mode == Mode.Disable)
				{
					foreach (Node targetNode2 in targetNodes)
					{
						targetNode2.inConnections[0].isActive = false;
					}
				}
				if (mode == Mode.Toggle)
				{
					foreach (Node targetNode3 in targetNodes)
					{
						targetNode3.inConnections[0].isActive = !targetNode3.inConnections[0].isActive;
					}
				}
				return Status.Success;
			}
			return Status.Failure;
		}
	}
}
